
import java.util.HashMap;

/**
 * @author zx
 * @date date 2019-12-04 15:21:44
 * ---------------------------
 * 滑动窗口
 * ---------------------------
 */
public class T3 {
    public static int lengthOfLongestSubString(String s){
        int r = 0, l = 0;
        int ans = 0xffffffff;
        HashMap<Character, Integer> windowCount = new HashMap<>();
        if(s.length() == 0){
            return 0;
        }

        while (r < s.length()){
            char cs_right = s.charAt(r);
            windowCount.put(cs_right,windowCount.getOrDefault(cs_right,0) + 1);
            while (windowCount.get(cs_right) > 1 && l < r){
                char cs_left = s.charAt(l);
                windowCount.put(cs_left, windowCount.get(cs_left) - 1);
                l++;
            }
            if(r - l + 1 > ans){
                ans = r - l + 1;
            }
            r++;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubString("bbb" ));

    }
}
